package cn.yangliu.springbatch.job;

import cn.yangliu.springbatch.entity.User;
import cn.yangliu.springbatch.repository.UserRepository;
import org.springframework.batch.core.annotation.BeforeWrite;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * the type of springbatch
 *
 * <p>
 * .
 *
 * @author 杨柳
 * @date 2021-07-12
 */
@Component
public class UserWriter implements ItemWriter<User> {

   /* @Inject
    private JobContext jobContext;*/

    @Autowired
    private UserRepository userRepository;

    @Override
    public void write(List<? extends User> list) throws Exception {
        userRepository.saveAllAndFlush(list);
    }

    @BeforeWrite
    public void test(List<? extends User> list) {
        System.out.println(list);
    }
}
